<template>

  <div class="home">
    <div class="header">
      <div class="header-left">
        <div class="header-left-img">
          <img src="../assets/img/logo.png" alt="">
        </div>
        <div class="header-left-right">
          <div class="header-left-title">小学刷题网</div>
          <div class="header-left-text">查缺补漏的好工具</div>
        </div>
        
      </div>
      <div class="header-center">
        <div class="header-center-title">学而时习之，不亦说乎！</div>
      </div>
      <div class="header-right">
        <div class="header-right-wrap">
            <div class="header-right-img"><img src="../assets/img/avatar.jpg" alt=""></div>
            <div class="username-text">{{username}}</div>
        </div>
        <div class="btn" @click="exit">退出登陆</div>
      </div>
    </div>
    <div class="nav">
      <div class="nav-item" @click="toTest(0)" :class="{active : this.$route.params.id === '0'}">
        <div class="nav-icon">
            <img src="../assets/img/easy.png" alt="">
        </div>
        <div class="nav-text">简单题</div>
      </div>
      <div class="nav-item" @click="toTest(1)" :class="{active : this.$route.params.id === '1'}">
        <div class="nav-icon">
            <img src="../assets/img/diff.png" alt="">
        </div>
        <div class="nav-text">困难题</div>
      </div>
      <div class="nav-item" @click="toRes()" :class="{active : this.$route.path === '/about/result'}">
        <div class="nav-icon">
            <img src="../assets/img/history.png" alt="">
        </div>
        <div class="nav-text">历史成绩</div>
      </div>
          
    </div>
    <router-view />
  </div>
</template>

<script>
export default {
  data() {
    return {
      username: ''
    };
  },
  mounted() {
    let user = JSON.parse(localStorage.getItem('user'));
    console.log(user);
    this.username = user.username;
    if(!user){
        this.$router.push('/login')
    }
    console.log(this.$route.params);
  },
  methods: {
    toTest(index) {
      if (index == this.$route.params.id) {
        return;
      }
      this.$router.push("/about/test/" + index);
    },
    toRes(){
        this.$router.push("/about/result")
    },
    exit(){
        localStorage.clear('user')
        this.$router.push('/login')
    }
  },
};
</script>

<style lang='less' scoped>
.home{
  margin-top: 120px;
  width: 100%;
  height: 2200px;
  background: url(../assets/img/homebg1.png);
  padding: 1px;
}
.header {
  // background:url(../assets/img/headbg.jpg)  100%;
  margin: 0 auto;
  width: 1200px;
  height: 120px;
  display: flex;
  margin-top: -120px;
  .header-left {
    flex: 1;
    // border: 1px solid #ccc;
    display: flex;
  }
  .header-left-img{
    margin:auto;
    width: 75px;
    height: 75px;
    flex:5;
    margin-right: 15px;
  }
  .header-left-right{
    display: flex;
    flex-direction: column;
  }
  .header-left-title{
    margin-top: 15px;
    width: 130px;
    height: 60;
    font-size: 25px;
    color: #186f70;
    line-height: 35px;
  }
  .header-left-text{
    margin-top: 5px;
    color: #ff0000;
    font-size: 16px;
    line-height: 25px;
    font-weight: normal;
  }
  .header-center {
    flex: 4;
    // border: 1px solid #ccc;
    margin: auto auto;
    text-align: center;
  }
  .header-center-title{
    color:#19a97b;
    font-size: 35px;
    // margin: auto;
  }
  .header-right {
    flex: 1;
    // border: 1px solid #ccc;
    display: flex;
    .username-text {
      // margin-top: 10px;
      height: 100%;
      // border: 1px solid;
    }

    
    .btn {
      margin:auto;
      height: 30px;
      width: 120px;
      padding: 4px 0;
      text-align: center;
      background-color: #38f;
      border-radius: 20px;
      cursor: pointer;
      color: #fff;
      user-select: none;
    }
    .btn:active {
      transform: scale(1.02);
    }
  }
}
.header-right-wrap{
  display: flex;
  flex-direction: column;
  margin-right:50px;
  margin-top:20px;
}
.username-text{
  font-weight:800;
  line-height: 25px;
  text-align: center;
  
}
.header-right-img{
  width: 75px;
  height: 75px;
  
}
.nav {
  // background: url(../assets/img/navbg.jpg) 100%;
  height: 120px;
  width: 1200px;
  // border: 1px solid #ccc;
  margin: 0 auto;
  margin-top: 20px;
  display: flex;
  justify-content: space-around;
  margin-top: 135px;
  margin-bottom: 50px;
  .nav-item {
    background-color:#5bdada;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    cursor: pointer;
    padding: 6px 20px;
    // border: 1px solid #ccc;
    .nav-icon {
      height: 75px;
      // border: 1px solid;
    }
    .nav-text {
      padding-top: 6px;
      margin: auto;
    }
  }
  .active{
      background-color: #37f;
      
  }
}
</style>